package com.android.takegism.utils;

import android.util.Log;

import androidx.annotation.Nullable;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class MiddlePuzzle extends PuzzleAbstract{

    private static List<String[]> QA = new LinkedList<>();
    static {
        QA.add(new String[]{"小黑人儿细又长，穿着木头花衣裳，画画写字它全会，就是不会把歌唱。(打一文具)", "铅笔"});
        QA.add(new String[]{"身体有圆也有方，常在铅笔盒里装，要是写错一个字，它会马上来帮忙。(打一文具)", "橡皮"});
        QA.add(new String[]{"白娃娃，爬黑墙，越爬个儿越变小，再也没法往上长。(打一文具)", "粉笔"});
        QA.add(new String[]{"身体长的细又长，天生美丽黑心肠，上平下尖纸上爬，越爬越短越心伤。(猜文具)", "铅笔"});
        QA.add(new String[]{"硬舌头，尖嘴巴，不吃饭，光喝茶。(猜用品)", "钢笔"});
        QA.add(new String[]{"它是我的好朋友，每个同学全都有，笔墨书本帮我拿，可我还得背它走。(打一物)", "书包"});
        QA.add(new String[]{"新时白头发，旧时变成黑，闲时戴帽子，忙时把帽摘。(猜文具)", "毛笔"});
        QA.add(new String[]{"身穿绿衣裳，肚里水汪汪，生的子儿多，个个黑脸膛。(猜一食物)", "西瓜"});
    }
    static {
        errorAnswers = new HashSet<>();
        for (int i = 0;i<QA.size();i++){
            errorAnswers.add(QA.get(0)[1]);
        }
        errorAnswers.add("猴子");
        errorAnswers.add("苹果");
        errorAnswers.add("菠萝");
        errorAnswers.add("老虎");
        errorAnswers.add("同学");
        errorAnswers.add("老师");
        errorAnswers.add("爸爸");
        errorAnswers.add("妈妈");
        errorAnswers.add("哥哥");
        errorAnswers.add("李子");
        errorAnswers.add("梨子");
        errorAnswers.add("动画片");
        errorAnswers.add("西红柿");
        errorAnswers.add("香蕉");
        errorAnswers.add("葡萄");
        errorAnswers.add("胶水");
        errorAnswers.add("刀");
        errorAnswers.add("哈密瓜");
        errorAnswers.add("尺子");
        errorAnswersList = new LinkedList<>(errorAnswers);
    }
    public MiddlePuzzle(@Nullable Clue clue) {
        super(clue);
        Random random = new Random();
        int i = random.nextInt(QA.size());
        setQuestion(QA.get(i)[0]);
        setAnswer(QA.get(i)[1]);
        setType("Middle");
        setHardLevel(2);
        Log.d("ANSWER",QA.get(i)[1]+"");
    }

    @Override
    public Object check(Object answer) throws Exception {
        if (answer instanceof String){
            if (answer.equals(getAnswer())) {
                LinkedList<Clue> middle_clues = (LinkedList<Clue>) MyContext.getInstance().getAllClues("update_clues");
                if(middle_clues==null){
                    middle_clues = new LinkedList<Clue>();
                }
                middle_clues.add(clue);
                MyContext.getInstance().setAllClues("update_clues",middle_clues);
                return clue.clue;
            }else{
                return null;
            }
        }
        throw new Exception("程序错误");
    }
}
